package com.itlong.cloud.commons;

import com.itlong.cloud.project.operate.ITimeTaskDeadMessageQueueServiceClient;
import com.itlong.cloud.utils.date.DateUtil;
import org.slf4j.Logger;import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.bind.annotation.RestController;

import java.util.Calendar;

/**
 * <desc>
 *      死信队列重试机制定时任务
 * </desc>
 *
 * @createDate 2018/01/29
 */
@EnableScheduling // 启用定时任务
@RestController
public class DeadMessageQueueTimeTask {
    private static Logger LOG = LoggerFactory.getLogger(DeadMessageQueueTimeTask.class);

    @Autowired
    ITimeTaskDeadMessageQueueServiceClient iTimeTaskDeadMessageQueueServiceClient;

    /**
     * <desc>
     *      定时任务检测错误的死信消息进行重发
     * </desc>
     *
     * @author Jiaqi.X
     * @creatDate 2017/11/10
     */
    @Scheduled(cron = "0 0/1 * * * ?") // 每5分钟执行一次
    public void RedirectSendDeadMessage() {
        try {
            iTimeTaskDeadMessageQueueServiceClient.autoRedirectSendDeadMessage();
//            LOG.info("【定时任务】消息队列死信重发执行成功，当前时间：" + DateUtil.format(Calendar.getInstance(), "yyyy-MM-dd HH:mm:ss"));
        }catch (Exception e){
            LOG.error("【定时任务】消息队列死信重发执行失败，当前时间：" + DateUtil.format(Calendar.getInstance(), "yyyy-MM-dd HH:mm:ss:"),e);
        }
    }
}
